#include <iostream>
using namespace std;
typedef long long ll;
ll t, n, k, flag;
ll def(ll a){
	ll b = a;
	ll c = 0;
	while(b){
		c = c * 10 + b % 10;
		b /= 10;
	}
	return c + a;
}
bool green(ll a){
	ll b = a;
	ll c = 0;
	while(b){
		c = c * 10 + b % 10;
		b /= 10;
	}
	if (c == a) return true;
	else return false;
}
int main(){
	cin >> t;
	while(t--){
		cin >> n >> k;
		flag = 0;
		for (int i = 0; i <= k; i++){
			if (green(n)){
				cout << n << " " << i << endl;
				flag = 1;
				break;
			}
			if (i != k) n = def(n);
		}
		if (!flag) cout << n << " " << -1 << endl;
	}
	return 0;
}
